package com.yzz.hzraisedust.hzraseidust.main.airquality;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.yzz.hzraisedust.hzraseidust.R;
import com.yzz.hzraisedust.hzraseidust.modelbean.AirQualityBean;
import com.yzz.hzraisedust.hzraseidust.modelbean.ProjectAirItemBean;

import org.w3c.dom.Text;

import java.util.List;

/**
 * Created by zhengzhen on 2017/8/28.
 */

public class AirQualityAdapter extends BaseAdapter{
    private List<ProjectAirItemBean> mItems;
    private Context mContext;
    public AirQualityAdapter(Context context,List<ProjectAirItemBean> items){
        mContext = context;
        mItems = items;
    }


    @Override
    public int getCount() {
        return mItems.size();
    }

    @Override
    public Object getItem(int i) {
        return mItems.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder = null;
        if(view == null){
            view = LayoutInflater.from(mContext).inflate(R.layout.air_quality_detail_item_value_layout,null,false);
            viewHolder = new ViewHolder();
            viewHolder.airQualityDetailTextView = view.findViewById(R.id.monitor_air_quality_name_textview);
            viewHolder.airPM2_5TextView = view.findViewById(R.id.monitor_air_pm2_5_textview);
            viewHolder.airPM10TextView = view.findViewById(R.id.monitor_air_pm10_textview);
            view.setTag(viewHolder);
        }
        if(viewHolder == null){
            viewHolder = (ViewHolder)view.getTag();
        }
        ProjectAirItemBean bean = mItems.get(i);
        if(bean.getPmDescribe()==null){
            bean.concute();
        }
        viewHolder.airQualityDetailTextView.setText(bean.getName());
        viewHolder.airPM2_5TextView.setText(""+bean.getPm2_5());
        viewHolder.airPM2_5TextView.setTextColor(bean.getPm2_5BakcgroudColor());
        viewHolder.airPM10TextView.setText(""+bean.getPm10());
        viewHolder.airPM10TextView.setTextColor(bean.getBackgroudColor());
        return view;
    }
    class  ViewHolder{
         TextView airQualityDetailTextView;
         TextView airPM2_5TextView;
         TextView airPM10TextView;
    }

}
